﻿@model IEnumerable<QBWeb.ViewModels.CurriculumViewModels>

<div class="row">
    @ViewBag.user
    @if (!Model.Any())
    {
        <p style="color: lightgray; font-size: 30px; text-align: center">无课程信息</p>
    }
    @foreach (var item in Model)
    {
        <div id="f_@item.Id" class="col-md-3" style="border: solid 1px lightgray; border-radius: 2px; margin: 8px; padding-bottom: 10px; width: 20%; position: relative; background: white">
            <button style="border: none; background: none; position: absolute; top: 5%; left: 90%" id="btnList_@item.Id" onmouseover="Trigger(@item.Id)" data-id="List1">
                <span class="layui-icon layui-icon-more-vertical"></span>
            </button>
            <h3 id="curriName_@item.Id">@item.CurriName</h3>
            <span>加课码：@item.CurriCode</span>
            <p>
                <span id="year_@item.Id"> @item.Years </span>
                <br />
                @if (int.Parse(item.Semester) == 1)
                {
                    <span id="semester_@item.Id">第一学期</span>
                }
                else
                {
                    <span id="semester_@item.Id">第二学期</span>
                }
            </p>
            <hr />
            <span>@item.NickName </span>
            <div style="position: absolute; top: 80%; left: 70%">
                <a href="~/Curricula/StuDetails/@item.Id" title="进入" class="layui-btn layui-btn-normal layui-btn-sm"> 进入</a>
            </div>
            <a style="visibility: hidden;" href="javascript:void(0);" id="linkToClass"></a>
        </div>


    }
</div>

<script>



    function Trigger(id) {
        var userId = $("#UserId").text().trim();
        layui.use('dropdown', function () {
            var dropdown = layui.dropdown
                , $ = layui.jquery;
            dropdown.render({
                elem: `#btnList_${id}`
                , show: true
                , data: [
                    {
                        title: "退出"
                        , id: "quit"
                    }]
                , click: function (data, othis) {
                    var elem = $(this.elem)
                        , listId = elem.data('id'); //表格列表的预埋数据
                    if (data.id === "quit") {
                        layer.confirm('确认退出？', { title: '提示' }, function (index) {

                            $.ajax({
                                type: "POST",
                                url: "/Curricula/QuitCurricula",
                                data: {
                                    CurriculumId: id,
                                    StudentId: userId
                                },
                                dataType: "json",
                                success: function (res) {
                                    if (res.tf === true) {
                                        layer.msg(res.msg, { time: 2000 });
                                        $(`#f_${id}`).remove();
                                    } else
                                        layer.msg(res.msg);

                                }, error: function () {
                                    layer.msg("未知错误");
                                }
                            });
                            layer.close(index);
                        });
                    }

                }
            });
        });
    }
</script>